package com.dxf.bigdata.D05_spark_again

import org.apache.spark.rdd.RDD
import org.apache.spark.{HashPartitioner, SparkConf, SparkContext}

/**
 * 重新分区
 */
object PartitionBy {

  def main(args: Array[String]): Unit = {

    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("app")

    val sc = new SparkContext(sparkConf)
//    val someNone: Some[Some.type] = Some(Some)


    val rdd: RDD[Int] = sc.makeRDD(List(1, 2, 3, 4),2)

    val mapRDD: RDD[(Int, Int)] = rdd.map((_, 1))

    //RDD -> PairRDDFunctions 隐式转换
    // 重新分区,如按照奇数,偶数分区
    mapRDD.partitionBy(new HashPartitioner(2)).saveAsTextFile("output2")




    //别忘记
    sc.stop()


  }
}